//
//  CancellationAccountViewController.m
//  ZheJiangSFDriver
//
//  Created by mac on 2020/1/10.
//  Copyright © 2020 GCY. All rights reserved.
//

#import "CancellationAccountViewController.h"
#import "verificationCenterViewController.h"
#import "CYWebViewViewController.h"

@interface CancellationAccountViewController ()
{
    BOOL _isCanCancellation;
    BOOL _isAgree;
}
@property (weak, nonatomic) IBOutlet UIView *bottomBgView;
@property (weak, nonatomic) IBOutlet UIButton *confrimButton;
@property (weak, nonatomic) IBOutlet UILabel *accountLabel;
@property (weak, nonatomic) IBOutlet UILabel *tipTextLabel;
@property (weak, nonatomic) IBOutlet UIButton *zhuXiaoXieYiBtn;

@end

@implementation CancellationAccountViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    _isCanCancellation = NO;
    _isAgree = YES;
    self.navigationItem.title = @"注销账号";
    
    self.view.backgroundColor = BackgroundColor;
    
    _accountLabel.textColor = Dark_TextColor;
    
    _tipTextLabel.textColor = Light_TextColor;
    
    _accountLabel.text = CJStringWithFormat(@"注销%@所绑定的账号", _phoneNum);
    
    cut(_confrimButton, BTN_BORDER_RADIUS);
    
    [_confrimButton setBackgroundColor:Theme_ColorValue];
    
    NSString *agreementStr = [NSString stringWithFormat:@"《%@平台司机账号注销须知》", APP_PlatformName];
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:[@"同意" stringByAppendingString:agreementStr]];
    [attString addAttribute:(NSString*)NSForegroundColorAttributeName value:Light_TextColor range:[_zhuXiaoXieYiBtn.titleLabel.text rangeOfString:@"同意"]];
    [attString addAttribute:(NSString*)NSForegroundColorAttributeName value:Theme_ColorValue range:[_zhuXiaoXieYiBtn.titleLabel.text rangeOfString:agreementStr]];
    [_zhuXiaoXieYiBtn setAttributedTitle:attString forState:UIControlStateNormal];
        
    [self getNetworkRequest];
}

- (void)layouView:(NSArray *)data {
    
    //    NSArray *tipArr = @[@"没有在途运单",@"运单全部结算完毕",@"账户余额已全部提现"];
    for (int i=0; i<data.count; i++) {
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 45*i, ScreenW, 45)];
        [_bottomBgView addSubview:bgView];
        
        UILabel *tepLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15.5f, 14, 14)];
        tepLabel.text = [NSString stringWithFormat:@"%d", i + 1];
        tepLabel.font = font(13);
        tepLabel.textAlignment = NSTextAlignmentCenter;
        cut(tepLabel, 7);
        [bgView addSubview:tepLabel];
        
        UILabel *promptLabel = [[UILabel alloc] initWithFrame:CGRectMake(tepLabel.cy_right + 8, 0, 300, bgView.cy_height)];
        promptLabel.text = data[i][@"name"];
        promptLabel.font = font(14);
        [bgView addSubview:promptLabel];
        
        
        if ([data[i][@"result"] boolValue]) {
            promptLabel.textColor = Dark_TextColor;
            cutBorder(tepLabel, 1, @"#4C5C72");
            tepLabel.textColor = Dark_TextColor;
        } else {
            promptLabel.textColor = [UIColor cy_colorWithHexString:@"#FB6243"];
            cutBorder(tepLabel, 1, @"#FB6243");
            tepLabel.textColor = [UIColor cy_colorWithHexString:@"#FB6243"];
        }
        
        if (i<2) {
            UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, bgView.cy_height-1, ScreenW-30, 1)];
            line.backgroundColor = BackgroundColor;
            [bgView addSubview:line];
        }
    }
}

- (void)getNetworkRequest {
    ///注意：用户是否符合条件列表是动态返回的，不是写死的，现在发货企业和车队长是3条，其他用户2条。
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], PARTY_BYE) withParameter:@{ @"token":[UserDefaultUtil valueForKey:USER_TOKEN],} withVC:self netName:@"用户注销：是否符合条件列表" success:^(id response, NSString *msg) {
  
//        NSLog(@"bool = %@", [msg boolValue] ? @"YES" : @"NO");
        
        _isCanCancellation = [msg boolValue];
        
        [self layouView: response];
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

- (IBAction)btnTypeClick:(UIButton *)sender {
    
    if (_isAgree == NO) {
        [XSInfoView showInfo:@"请先同意注销须知" onView:self.view];
        return;
    }
    
    if (_isCanCancellation) {
        
        verificationCenterViewController *vcvc = [[verificationCenterViewController alloc] init];
        [self.navigationController pushViewController:vcvc animated:YES];
        
    } else {
        
        [XSInfoView showInfo:@"您未达到可以注销的条件，请检查" onView:self.view];
        
    }
}

- (IBAction)accountZhuXiaoXieYiAction:(UIButton *)sender {
    if (sender.selected) {
        _isAgree = YES;
        [sender setImage:[image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue] forState:UIControlStateNormal];
    } else {
        _isAgree = NO;
        [sender setImage:image(@"gcy_img_home_business_nomal") forState:UIControlStateNormal];
    }
    sender.selected = !sender.selected;
}
- (IBAction)checkXieYiAction:(UIButton *)sender {
    
    CYWebViewViewController *webVC = [[CYWebViewViewController alloc] init];
    webVC.titleString = @"账号注销须知";
    webVC.urlString = CJStringWithFormat(@"%@/agreement/agreement.html?agreementType=3", BasicDomainURL);
    webVC.state = 1;
    [self.navigationController pushViewController:webVC animated:YES];
}

@end
